package com.diaosidadui.test;

import java.util.Scanner;

public class FlowerNum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int getNum = sc.nextInt();
        StringBuilder st = new StringBuilder();
        st.append(getNum);
        if (st.length() < 1 || st.length() > 5) {
            System.out.println("超出范围");
        } else {
            st.delete(0, st.length());
            lo:
            for (int num = 0; num <= getNum; num++) {
                //得到 num
                int ge = num % 10;
                int shi = num / 10 % 10;
                int bai = num / 10 / 10 % 10;
                int qian = num / 10 / 10 / 10 % 10;
                int wan = num / 10000 % 10;
                st.append(num);

                switch (st.length()) {
                    case 1://1位数
                        boolean isFlower1 = num == ge;
                        if (isFlower1) {
                            System.out.println(num);
                        }
                        st.delete(0, st.length());
                        break;
                    case 2://2位数
                        boolean isFlower2 = num == ge * ge + shi * shi;
                        if (isFlower2) {
                            System.out.println(num);
                        }
                        st.delete(0, st.length());
                        break;
                    case 3://3位数
                        boolean isFlower3 = num == power(ge,3)+power(shi,3)+power(bai,3);
                        if (isFlower3) {
                            System.out.println(num);
                        }
                        st.delete(0, st.length());
                        break;
                    case 4://4位数
                        boolean isFlower4 = num == power(ge,34)+power(shi,4)+power(bai,4)+power(qian,4);
                        if (isFlower4) {
                            System.out.println(num);
                        }
                        st.delete(0, st.length());
                        break;
                    case 5://4位数
                        boolean isFlower5 = num == power(ge,5)+power(shi,5)+power(bai,5)+power(qian,5)+power(wan,5);
                        if (isFlower5) {
                            System.out.println(num);
                        }
                        st.delete(0, st.length());
                        break;
                }


            }

        }
//

    }


    public static double power(double x, int n) {
//        double  x =sc.nextDouble();
        double multiply = 1;
//        int  n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            multiply = multiply * x;
        }
        return multiply;
    }
}



